#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time    : 2023/12/25 16:34
# @Author : 闫峰
# @File    : init_logger.py
import os

from common.setting import ensure_path_sep
from utils.logging_tool.log_control import LogHandler


def init_logger():
    current_path = os.path.abspath(__file__)
    # current_dir = os.path.dirname(current_path)
    path_list = current_path.split("\\")
    dis_path = "\\".join(path_list[-2:-1])

    def remove_file(info_path):
        if os.path.exists(info_path):
            os.remove(info_path)
        else:
            print(f"{info_path} 不存在")

    pid = os.getpid()
    info_path = ensure_path_sep(f"\\logs\\info-{dis_path}{pid}")
    error_path = ensure_path_sep(f"\\logs\\\error-{dis_path}{pid}.log")
    warning_path = ensure_path_sep(f"\\logs\\warning-{dis_path}{pid}.log")
    remove_file(info_path)
    remove_file(error_path)
    remove_file(warning_path)
    INFO = LogHandler(info_path, level='info')
    ERROR = LogHandler(error_path, level='error')
    WARNING = LogHandler(warning_path, level='warning')
    return INFO, ERROR, WARNING